package controllers

import (
	"demo/models"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"strings"
)

type OrderController struct {
	beego.Controller
}

type Sum struct {
	Count int
}

func (this *OrderController) ApiFunc() {
	page := this.GetString("page")
	size := this.GetString("size")
	keys := this.GetString("search")

	o := orm.NewOrm()
	//查询订单列表
	var order []models.RechargeOrder
	sql := strings.Join([]string{"select * from `yk_recharge_order` where order_sn='", keys, "' order by id desc limit ", page, ",", size}, "")
	_, err := o.Raw(sql).QueryRows(&order)
	if err != nil {
		beego.Info("错误信息:", err);
		return
	}
	beego.Info(order)
	var count []Sum
	sql = "select count(*) as count from `yk_recharge_order`"
	_, err = o.Raw(sql).QueryRows(&count)
	if err != nil {
		beego.Info("错误信息:", err);
		return
	}
	this.Data["json"] = map[string]interface{}{"code":200,"msg":"请求成功","count":count[0].Count,"data":order}
	this.ServeJSON();
	return
}
